
<template>
  <div id="about">
    <tabletitle
      :get-all-data="getAllData"
      :add-user-data="addUser"
    ></tabletitle>

    <tablebody
    :data-change-sex='dataChangeSex'
    :handle-delete-item='handleDeleteItem'
    :edit-text='editText'
    :delete-item='deleteItem'
    :is-show='isShow'
    ></tablebody>
  <a-modal v-model="showText"  @ok="commitEdit">
    <div>
       <a-input :placeholder="popData.name" style="width: 200px"/>
      <div>性别</div>
        <a-select  name="" id="" v-model="popData.sex">
         
       <a-select-option value="男">
        男
      </a-select-option>
      <a-select-option value="女">
       女
      </a-select-option>
         </a-select>
         <div>权限分配</div>
         <a-select name="" id="" v-model="popData.lv">
          <a-select-option v-for="item in $options.lvOptions" :key="item.value">
            {{ item.label }}
          </a-select-option>
        </a-select>
        </div>
    </a-modal>
    <!-- <Popup
      :is-show="showText"
      :fillter="Set_Sex"
      :noedit="noedit"
      :pop-data="popData"
      :lv-options="$options.lvOptions"
      :add-user="addUserData"
      :commit-edit="commitEdit"
    >
      {{ popText }}
    </Popup> -->
     <a-modal v-model="isShow"  @ok="handleEnter">
      <p> 你确定要删除{{ deleteItem.name }}</p>
      
    </a-modal>
  </div>
</template>


<script>
import tablebody from "./../components/tablebody.vue";
import tabletitle from "./../components/tabletitle.vue";
import { post } from "../../utils/request";
// import Model from "../../components/Model/index.vue";
// import Popup from "../../components/Model/edit.vue";
import { Set_Sex ,LV_OPTIONS} from "./config";
export default {
  components: {
    // Model,
    // Popup,
    tabletitle,
    tablebody,
  },
   lvOptions: LV_OPTIONS,
  data() {
    return {
      listData: [],
      Set_Sex,
      isShow: false,
      showText: false,
      deleteItem: "",
      popData: {},
      popText: "修改",
    };
  },

  mounted() {
    //初始化获取数据
    this.getAllData();
  },
  computed: {
    //更换数据
    dataChangeSex() {
      return this.listData.map((item) => ({ ...item, sex: Set_Sex[item.sex],key:item.id }));
    },
  },
  methods: {
    //搜索获取数据
    editText(item) {
      this.popData = item;
      this.showText = true;
    },
    noedit() {
      this.showText = false;
    },
    commitEdit() {
      post("/getdata", this.popData).then((res) => {
        this.listData = res;
      });
      this.showText = false;
    },
    getAllData(params) {
      post("/getdata", params).then((res) => {
        this.listData = res;
      });
    },
    addUserData(params) {
      post("/adduser", params);
    },
    handleDeleteItem(item) {
          this.deleteItem = item;
          this.isShow = true;
    },
    addUser(){
     this.popText='添加'
     this.popData={}
      this.showText=true
   },
    // handleCancel() {
    //   this.isShow = false;
    // },
   
    handleEnter() {
      this.getAllData(this.deleteItem);
      this.isShow = false;
    },
  },
};
</script>

<style scoped>

</style>
